package cn.wen.yinxiu.member.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.wen.yinxiu.common.toolkit.PageUtils;
import cn.wen.yinxiu.common.toolkit.Query;

import cn.wen.yinxiu.member.dao.UserGroupRelationDao;
import cn.wen.yinxiu.member.entity.UserGroupRelationEntity;
import cn.wen.yinxiu.member.service.UserGroupRelationService;


@Service("userGroupRelationService")
public class UserGroupRelationServiceImpl extends ServiceImpl<UserGroupRelationDao, UserGroupRelationEntity> implements UserGroupRelationService {

    @Autowired
    private UserGroupRelationDao userGroupRelationDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<UserGroupRelationEntity> page = this.page(
                new Query<UserGroupRelationEntity>().getPage(params),
                new QueryWrapper<UserGroupRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public boolean exitGroup(Long userId, Long groupId) {
        UserGroupRelationEntity target = new UserGroupRelationEntity();
        target.setGroupId(groupId);
        target.setUserId(userId);
        return userGroupRelationDao.updateById(target) > 0;
    }

}